home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- * This file contains the bulk of the program. All of the dialog box
- * stuff is performed in this file.
- **********************************************************************/
-
- #include "Creator Changer.h"
- #include "Creator Changer.dialog.h"
-
-
- /**********************************************************************
- * Function Open_DLOG(), this function is a general function for
- * opening all of the Dialog boxes in the program.
- **********************************************************************/
-
- void Open_DLOG(Dialog_Info *the)
- {
-
- Handle item_handle;
-
- if(proc_for_draw_Chng_dialog==NIL_PTR) proc_for_draw_Chng_dialog=NewUserItemProc(Draw_Chng_Dialog);
- if(proc_for_draw_Pref_dialog==NIL_PTR) proc_for_draw_Pref_dialog=NewUserItemProc(Draw_Pref_Dialog);
- if(proc_for_draw_Abot_dialog==NIL_PTR) proc_for_draw_Abot_dialog=NewUserItemProc(Draw_Abot_Dialog);
-
- if(Has_Drag_Mgr)
- {
- if(drag_tracking==NIL_PTR) drag_tracking=NewDragTrackingHandlerProc(Handle_Drag_Tracking);
- if(drag_receiver==NIL_PTR) drag_receiver=NewDragReceiveHandlerProc(Handle_Drag_Receive_Drop);
- }
-
- the->dialog=GetNewDialog(the->dlog_id, the->storage, IN_FRONT);
-
- if(the->dialog==Chng.dialog)
- {
- Make_Pop_Up_Menu(the->menu_id, the->pref_type, the->num_items);
- Set_Dialog_Proc((Handle)proc_for_draw_Chng_dialog, Chng.dialog, CHNG_DLOG_UI);
- if(!Multiple_Files)
- {
- Set_Type_Text(F_Type, File_Info.fdType);
- Set_Type_Text(C_Type, File_Info.fdCreator);
- }
- if(Has_Drag_Mgr)
- {
- InstallTrackingHandler(drag_tracking, Chng.dialog, (void *)NIL_PTR);
- InstallReceiveHandler(drag_receiver, Chng.dialog, (void *)NIL_PTR);
- }
- }
- else if(the->dialog==About.dialog) Set_Dialog_Proc((Handle)proc_for_draw_Abot_dialog, About.dialog, ABOUT_DLOG_UI);
- else if(the->dialog==Pref.dialog)
- {
- Get_Dialog_Item_Hndl(the->dialog, PREF_POPUP, &item_handle);
- Handle_Pref_Pop_Up_Menu(the, YES);
-
- if(Has_Drag_Mgr)
- {
- InstallTrackingHandler(drag_tracking, Pref.dialog, (void *)NIL_PTR);
- InstallReceiveHandler(drag_receiver, Pref.dialog, (void *)NIL_PTR);
- }
-
- }
- Maintain_Menu_Items(FrontWindow());
-
- }
-
-
-
- /**********************************************************************
- * Function Switch_Chng_Dialog(), this function decides where events
- * in the Change Dialog box should go.
- **********************************************************************/
-
- void Switch_Chng_Dialog(Dialog_Info *the, short item_hit)
- {
-
- switch(item_hit)
- {
- case CHNG_OK:
- Handle_Chng_OK(the->dialog, &the->files, the->num_files, CHNG_CREATOR, CHNG_FILE);
- break;
- case CHNG_POP_UP:
- Handle_Pt_Pop_Up(the->dialog, CHNG_POP_UP, CHNG_CREATOR, CHNG_FILE, NO);
- break;
- case CHNG_CANCEL:
- if(Has_Drag_Mgr)
- {
- RemoveTrackingHandler(drag_tracking, the->dialog);
- RemoveReceiveHandler(drag_receiver, the->dialog);
- }
- CloseDialog(the->dialog);
- Done_With_Dialog=YES;
- Maintain_Menu_Items(FrontWindow());
- break;
- case CHNG_MKLK:
- Handle_Make_Like(the->dialog, CHNG_FILE, CHNG_CREATOR, NIL_PTR);
- break;
- case CHNG_CRNT_CREATOR:
- if(!Multiple_Files) Set_DLOG_Text_Item(the->dialog, CHNG_CREATOR, C_Type);
- break;
- case CHNG_CRNT_TYPE:
- if(!Multiple_Files) Set_DLOG_Text_Item(the->dialog, CHNG_FILE, F_Type);
- break;
- }
-
- }
-
-
- /**********************************************************************
- * Function Switch_Pt_Dialog(), this function decides where events
- * in the Edit DITL should go. This is part of the Preference Dialog.
- **********************************************************************/
-
- void Switch_Pt_Dialog(Dialog_Info *the, short item_hit)
- {
-
- short os=the->num_items;
-
- switch(item_hit-os)
- {
- case P_PT_PM:
- Handle_Pt_Pop_Up(the->dialog, os+P_PT_PM, os+P_PT_CT, os+P_PT_FT, os+P_PT_DS);
- break;
- case P_PT_ADD:
- Handle_Pt_Add_Item(the->dialog, os+P_PT_CT, os+P_PT_FT, os+P_PT_DS);
- break;
- case P_PT_DEL:
- Handle_Pt_Del_Item();
- break;
- case P_PT_GFL:
- Handle_Make_Like(the->dialog, os+P_PT_FT, os+P_PT_CT, NIL_PTR);
- break;
- }
-
- }
-
-
- /**********************************************************************
- * Function Switch_Ac_Dialog(), this function decides where events
- * in the Auto DITL should go. This is part of the Preference Dialog.
- **********************************************************************/
-
- void Switch_Ac_Dialog(Dialog_Info *the, short item_hit)
- {
-
- short os=the->num_items;
-
- switch(item_hit-os)
- {
- case P_AC_POPM:
- Handle_Ac_Pop_Up(the->dialog, os+P_AC_POPM, os+P_AC_CHFT, os+P_AC_CTCT, os+P_AC_CTFT);
- break;
- case P_AC_ADD:
- Handle_Ac_Add_Item(the->dialog, os+P_AC_CHFT, os+P_AC_CTCT, os+P_AC_CTFT);
- break;
- case P_AC_DEL:
- Handle_Ac_Del_Item();
- break;
- case P_AC_GFL:
- Handle_Make_Like(the->dialog, os+P_AC_CTFT, os+P_AC_CTCT, os+P_AC_CHFT);
- break;
- }
-
- }
-
-
- /**********************************************************************
- * Function Switch_Abot_Dialog(), this function decides where events
- * in the About Dialog should go.
- **********************************************************************/
-
- void Switch_Abot_Dialog(Dialog_Info *the, short item_hit)
- {
-
- switch(item_hit)
- {
- case ABOUT_OK:
- CloseDialog(the->dialog);
- Maintain_Menu_Items(FrontWindow());
- break;
- }
-
- }
-
-
- /**********************************************************************
- * Function Switch_Pref_Dialog(), this function decides where events
- * in the Preference Dialog box should go.
- **********************************************************************/
-
- void Switch_Pref_Dialog(Dialog_Info *the, short item_hit)
- {
-
- switch(item_hit)
- {
- case PREF_POPUP:
- Handle_Pref_Pop_Up_Menu(the, NO);
- break;
- case PREF_DONE:
- if(Has_Drag_Mgr)
- {
- RemoveTrackingHandler(drag_tracking, the->dialog);
- RemoveReceiveHandler(drag_receiver, the->dialog);
- }
- CloseDialog(the->dialog);
- the->menu_id=NIL_PTR;
- Maintain_Menu_Items(FrontWindow());
- default:
- Handle_Pref_DITL_Item(the, item_hit);
- break;
- }
-
- }
-
-
-
- /**********************************************************************
- * Function Switch_Gnrl_Dialog(), this function decides where events
- * in the General DITL should go. This is part of the Preference Dialog.
- **********************************************************************/
-
- void Switch_Gnrl_Dialog(Dialog_Info *the, short item_hit)
- {
-
- short os=the->num_items;
-
- switch(item_hit-os)
- {
- case P_GN_OKAC:
- UseResFile(CreatorChangerPref);
- (**Global).AutoChange=Handle_Check_Item(the->dialog, os+P_GN_OKAC);
- ChangedResource((Handle)Global);
- UpdateResFile(CreatorChangerPref);
- UseResFile(CreatorChangerApp);
- break;
- case P_GN_QADD:
- UseResFile(CreatorChangerPref);
- (**Global).DragQuit=Handle_Check_Item(the->dialog, os+P_GN_QADD);
- ChangedResource((Handle)Global);
- UpdateResFile(CreatorChangerPref);
- UseResFile(CreatorChangerApp);
- break;
- }
-
- }
-
-
- /**********************************************************************
- * Function Handle_Chng_OK(), this function changes the file and
- * creator types of the file(s) opened.
- **********************************************************************/
-
- void Handle_Chng_OK(DialogRef the_dialog, AEDescList *the_files, long num_of_files, short creator, short file)
- {
-
- short register i;
- short temp;
- AEKeyword key_word;
- DescType the_type;
- Size the_size;
- Str4 the_text;
-
- temp=Check_Data(the_dialog, file, NO)+Check_Data(the_dialog, creator, NO);
-
- if(temp<TYPE_LEN)
- {
- for(i=1;i<=num_of_files;i++)
- {
- if(Multiple_Files)
- {
- AEGetNthPtr(the_files, i, typeFSS, &key_word, &the_type, &The_File_Spec, sizeof(The_File_Spec), &the_size);
- FSpGetFInfo(&The_File_Spec, &File_Info);
- }
- Get_Dialog_Text(the_text, the_dialog, CHNG_FILE);
- Set_Type_Long(the_text, &File_Info.fdType, the_dialog, file);
- Get_Dialog_Text(the_text, the_dialog, CHNG_CREATOR);
- Set_Type_Long(the_text, &File_Info.fdCreator, the_dialog, creator);
- FSpSetFInfo(&The_File_Spec, &File_Info);
- }
- Force_Finder_Update(&The_File_Spec);
- if(Multiple_Files) AEDisposeDesc(the_files);
- CloseDialog(the_dialog);
- Maintain_Menu_Items(FrontWindow());
- Done_With_Dialog=YES;
- }
- else Do_Error(Types_Error_1, EMPTY_STR, Types_Error_2, EMPTY_STR);
-
- }
-
-
-
- /**********************************************************************
- * Function Set_Type_Long(), this function converts a string in an
- * edit field to an OStype.
- **********************************************************************/
-
- void Set_Type_Long(Str4 in_the_text_type, OSType *out_the_ostype, DialogRef the_dialog, short ID)
- {
-
- register short i;
- Byte *temp;
-
- temp=(Byte *)out_the_ostype;
-
- for(i=0;i<TYPE_LEN;++i) temp[i]=in_the_text_type[i+1];
-
- }
-
-
-
- /**********************************************************************
- * Function Set_Type_Text(), this function sets the text for the file
- * and creator types given an usigned decimal file / creator type.
- **********************************************************************/
-
- void Set_Type_Text(Str4 out_the_text_type, OSType in_the_ostype)
- {
-
- register short i;
- Byte *temp;
-
- out_the_text_type[0]=TYPE_LEN;
-
- temp=(Byte *)&in_the_ostype;
- for(i=0;i<TYPE_LEN;++i) out_the_text_type[i+1]=temp[i];
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Make_Like(), this function picks a file to use as
- * a template.
- **********************************************************************/
-
- void Handle_Make_Like(DialogRef the_dialog, short file, short creator, short from_file)
- {
-
- Str4 f_type, c_type;
- FSSpec ml_file_spec;
- FInfo ml_file_info;
-
- if(Pick_File(&ml_file_spec, &ml_file_info, FALSE))
- {
- Set_Type_Text(f_type, ml_file_info.fdType);
- Set_Type_Text(c_type, ml_file_info.fdCreator);
-
- if(from_file) Set_DLOG_Text_Item(the_dialog, from_file, f_type);
- Set_DLOG_Text_Item(the_dialog, file, f_type);
- Set_DLOG_Text_Item(the_dialog, creator, c_type);
- }
- PT_Item_To_Edit=AC_Item_To_Edit=0;
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Pt_Add_Item(), this function actually does the adding
- * of the items to the preferences file.
- **********************************************************************/
-
- void Handle_Pt_Add_Item(DialogRef the_dialog, short creator, short file, short description)
- {
-
- short temp;
- pref_types **rsrc_handle;
-
- temp=Check_Data(the_dialog, file, NO)+Check_Data(the_dialog, creator, NO)+Check_Data(the_dialog, description, YES);
-
- if(temp<TYPE_LEN)
- {
- UseResFile(CreatorChangerPref);
- rsrc_handle=(pref_types **)NewHandle(sizeof(pref_types));
-
- Get_Dialog_Text((**rsrc_handle).Description, the_dialog, description);
- Get_Dialog_Text((**rsrc_handle).CreatorType, the_dialog, creator);
- Get_Dialog_Text((**rsrc_handle).FileType, the_dialog, file);
-
- AddResource((Handle)rsrc_handle, PREF_PT, Chng.num_items==0 ? Strt_Rsrc : The_pt_Type[Chng.num_items]+1, (**rsrc_handle).Description);
- ChangedResource((Handle)rsrc_handle);
- UpdateResFile(CreatorChangerPref);
- Chng.num_items=Edit.num_items=CountResources(PREF_PT);
- ReleaseResource((Handle)rsrc_handle);
- UseResFile(CreatorChangerApp);
- Make_Pop_Up_Menu(PREF_TYPES_ID, PREF_PT, Chng.num_items);
- PT_Item_To_Edit=0;
- }
- else if(temp<=TYPE_LEN+TYPE_LEN+1) Do_Error(Types_Error_1, EMPTY_STR, Types_Error_2, EMPTY_STR);
- else if(temp==DESC_LEN+2) Do_Error(Descr_Error, EMPTY_STR, EMPTY_STR, EMPTY_STR);
- else Do_Error(Types_Error_1, Descr_Error, EMPTY_STR, EMPTY_STR);
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Pt_Del_Item(), this function actually does the
- * deleting of the item from the preferences file.
- **********************************************************************/
-
- void Handle_Pt_Del_Item(void)
- {
-
- short resource_number, i;
- pref_types **rsrc_handle;
-
- if(PT_Item_To_Edit)
- {
- UseResFile(CreatorChangerPref);
- resource_number=The_pt_Type[PT_Item_To_Edit];
- rsrc_handle=(pref_types **)NewHandle(sizeof(pref_types));
- rsrc_handle=(pref_types **)GetResource(PREF_PT, resource_number);
- RemoveResource((Handle)rsrc_handle);
- ReleaseResource((Handle)rsrc_handle);
- UpdateResFile(CreatorChangerPref);
- for(i=(resource_number+1);i<=The_pt_Type[Chng.num_items];i++)
- {
- rsrc_handle=(pref_types **)GetResource(PREF_PT, i);
- DetachResource((Handle)rsrc_handle);
- AddResource((Handle)rsrc_handle, PREF_PT, i-1, NIL_PTR);
- ChangedResource((Handle)rsrc_handle);
- ReleaseResource((Handle)rsrc_handle);
-
- rsrc_handle=(pref_types **)GetResource(PREF_PT, i);
- RemoveResource((Handle)rsrc_handle);
- ChangedResource((Handle)rsrc_handle);
- ReleaseResource((Handle)rsrc_handle);
- }
- UpdateResFile(CreatorChangerPref);
- Chng.num_items=Edit.num_items=CountResources(PREF_PT);
- UseResFile(CreatorChangerApp);
- Make_Pop_Up_Menu(PREF_TYPES_ID, PREF_PT, Chng.num_items);
- PT_Item_To_Edit=0;
- }
- else Do_Error(Bad_Item_Error, EMPTY_STR, EMPTY_STR, EMPTY_STR);
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Ac_Add_Item(), this function actually does the adding
- * of the items to the preferences file.
- **********************************************************************/
-
- void Handle_Ac_Add_Item(DialogRef the_dialog, short from_file_id, short to_creator_id, short to_file_id)
- {
-
- OSType long_from_file;
- short temp;
- auto_chng **rsrc_handle;
- Str4 types[100];
-
- temp=Check_Data(the_dialog, from_file_id, NO)+Check_Data(the_dialog, to_creator_id, NO)+Check_Data(the_dialog, to_file_id, NO);
-
- if(temp<TYPE_LEN)
- {
- Get_Types_From_Prefs(types);
- Set_Type_Long(NIL_PTR, &long_from_file, the_dialog, from_file_id);
- if(Check_File_Type(types, long_from_file)) Do_Error(Bad_CF_Type_1, Bad_CF_Type_2, Bad_CF_Type_3, Bad_CF_Type_4);
- else
- {
- rsrc_handle=(auto_chng **)NewHandle(sizeof(auto_chng));
-
- Get_Dialog_Text((**rsrc_handle).FromFile, the_dialog, from_file_id);
- Get_Dialog_Text((**rsrc_handle).ToCreator, the_dialog, to_creator_id);
- Get_Dialog_Text((**rsrc_handle).ToFile, the_dialog, to_file_id);
-
- Make_Ac_Name((**rsrc_handle).Name, (**rsrc_handle).FromFile, (**rsrc_handle).ToCreator, (**rsrc_handle).ToFile);
- UseResFile(CreatorChangerPref);
- AddResource((Handle)rsrc_handle, PREF_AC, Auto.num_items==0 ? Strt_Rsrc : The_ac_Type[Auto.num_items]+1, (**rsrc_handle).Name);
- ChangedResource((Handle)rsrc_handle);
- UpdateResFile(CreatorChangerPref);
- Auto.num_items=CountResources(PREF_AC);
- UseResFile(CreatorChangerApp);
- ReleaseResource((Handle)rsrc_handle);
- }
- Make_Pop_Up_Menu(AUTO_CHANGE_ID, PREF_AC, Auto.num_items);
- AC_Item_To_Edit=0;
- }
- else Do_Error(Types_Error_1, EMPTY_STR, EMPTY_STR, EMPTY_STR);
-
- }
-
-
-
- /**********************************************************************
- * Function Make_Ac_Name(), this function makes the name
- * which shows up in the pop-up menu for the auto change items.
- **********************************************************************/
-
- void Make_Ac_Name(StringPtr name, StringPtr from_file, StringPtr to_creator, StringPtr to_file)
- {
-
- register short i;
-
- name[0]=16;
- for(i=1;i<=4;i++) name[i]=from_file[i];
- name[5]='-';
- name[6]='>';
- for(i=7;i<=10;i++) name[i]=to_creator[i-6];
- name[11]=',';
- name[12]=' ';
- for(i=13;i<=16;i++) name[i]=to_file[i-12];
-
- }
-
-
- /**********************************************************************
- * Function Handle_Ac_Del_Item(), this function deletes items
- * from the auto change item list.
- **********************************************************************/
-
- void Handle_Ac_Del_Item(void)
- {
-
- short resource_number, i;
- auto_chng **rsrc_handle;
-
- if(AC_Item_To_Edit)
- {
- UseResFile(CreatorChangerPref);
- resource_number=The_ac_Type[AC_Item_To_Edit];
- rsrc_handle=(auto_chng **)NewHandle(sizeof(auto_chng));
- rsrc_handle=(auto_chng **)GetResource(PREF_AC, resource_number);
- RemoveResource((Handle)rsrc_handle);
- ReleaseResource((Handle)rsrc_handle);
- UpdateResFile(CreatorChangerPref);
- for(i=(resource_number+1);i<=The_ac_Type[Auto.num_items];i++)
- {
- rsrc_handle=(auto_chng **)GetResource(PREF_AC, i);
- DetachResource((Handle)rsrc_handle);
- AddResource((Handle)rsrc_handle, PREF_AC, i-1, NIL_PTR);
- ChangedResource((Handle)rsrc_handle);
- ReleaseResource((Handle)rsrc_handle);
-
- rsrc_handle=(auto_chng **)GetResource(PREF_AC, i);
- RemoveResource((Handle)rsrc_handle);
- ChangedResource((Handle)rsrc_handle);
- ReleaseResource((Handle)rsrc_handle);
- }
- UpdateResFile(CreatorChangerPref);
- Auto.num_items=CountResources(PREF_AC);
- UseResFile(CreatorChangerApp);
- Make_Pop_Up_Menu(AUTO_CHANGE_ID, PREF_AC, Auto.num_items);
- AC_Item_To_Edit=0;
- }
- else Do_Error(Bad_Item_Error, EMPTY_STR, EMPTY_STR, EMPTY_STR);
-
- }
-
-
- /**********************************************************************
- * Function Handle_Check_Item(), this function either checks or
- * unchecks a check box item.
- **********************************************************************/
-
- Boolean Handle_Check_Item(DialogRef the_dialog, short dialog_item)
- {
-
- Boolean value;
- Handle the_handle;
-
- Get_Dialog_Item_Hndl(the_dialog, dialog_item, &the_handle);
- value=GetControlValue((ControlHandle)the_handle);
-
- if(value==TRUE)
- {
- SetControlValue((ControlHandle)the_handle, FALSE);
- return(FALSE);
- }
- else if(value==FALSE)
- {
- SetControlValue((ControlHandle)the_handle, TRUE);
- return(TRUE);
- }
-
- }
-
-
- /**********************************************************************
- * Function Draw_Default_Border(), this function draws the border
- * around the item sent to it, that is within the specified dialog box
- **********************************************************************/
-
- void Draw_Border(DialogRef the_dialog, short the_item, short is_default)
- {
-
- short diameter;
- Rect item_rect;
- GrafPtr old_port;
-
- GetPort(&old_port);
- SetPort(the_dialog);
-
- Get_Dialog_Item_Rect(the_dialog, the_item, &item_rect);
- if(is_default)
- {
- diameter=(item_rect.bottom-item_rect.top)/2+6;
- if(diameter<16) diameter=16;
- PenSize(3, 3);
- InsetRect(&item_rect, -4, -4);
- FrameRoundRect(&item_rect, diameter, diameter);
- }
- else
- {
- PenSize(1, 1);
- FrameRect(&item_rect);
- }
-
- SetPort(old_port);
-
- }
-
-
-
- /**********************************************************************
- * Function Draw_Chng_Crnt_Type(), this function handels what happens
- * if a key is pressed.
- **********************************************************************/
-
- void Draw_Chng_Crnt_Type(DialogRef the_dialog)
- {
-
- Rect item_rect;
- GrafPtr old_port;
-
- TextFont(systemFont);
- TextSize(12);
- TextFace(0);
-
- GetPort(&old_port);
- SetPort(the_dialog);
-
- Draw_Border(the_dialog, CHNG_CRNT_CREATOR, NO);
- Get_Dialog_Item_Rect(the_dialog, CHNG_CRNT_CREATOR, &item_rect);
- MoveTo(item_rect.left+4, item_rect.bottom-7);
- DrawString(C_Type);
-
- Draw_Border(the_dialog, CHNG_CRNT_TYPE, NO);
- Get_Dialog_Item_Rect(the_dialog, CHNG_CRNT_TYPE, &item_rect);
- MoveTo(item_rect.left+4, item_rect.bottom-7);
- DrawString(F_Type);
-
- SetPort(old_port);
-
- }
-
-
-
- /**********************************************************************
- * Function Check_Data(), this function checks the type entered
- * by the user. If there are more than 4 charachters than there is
- * an error, and if there is no data entered in there is an error.
- **********************************************************************/
-
- short Check_Data(DialogRef the_dialog, short ID, short is_desc)
- {
-
- Str255 the_error;
- short the_type_len, len;
- Str32 item_text;
-
- Get_Dialog_Text(item_text, the_dialog, ID);
- len=item_text[0];
- if(is_desc) the_type_len=DESC_LEN;
- else the_type_len=TYPE_LEN;
- if(len!=the_type_len && the_type_len==TYPE_LEN) return(TYPE_LEN);
- else if((len>the_type_len && the_type_len==DESC_LEN) || len==0) return(DESC_LEN);
- else return(GOOD);
-
- }
-
-
-
- /**********************************************************************
- * Function Set_DLOG_Text_Item(), this function sets text boxes in the
- * selected dialog to the text which is sent to it.
- **********************************************************************/
-
- void Set_DLOG_Text_Item(DialogRef the_dialog, short ID, StringPtr the_text)
- {
-
- Handle the_handle;
-
- Get_Dialog_Item_Hndl(the_dialog, ID, &the_handle);
- SetDialogItemText(the_handle, the_text);
-
- }
-
-
-
- /**********************************************************************
- * Function Draw_Chng_Dialog(), this function draws the objects in the
- * Change dialog box.
- **********************************************************************/
-
- static pascal void Draw_Chng_Dialog(DialogRef the_dialog, short blank_item)
- {
-
- Rect item_rect;
- GrafPtr old_port;
-
- GetPort(&old_port);
- SetPort(the_dialog);
-
- if(!Multiple_Files) Draw_Chng_Crnt_Type(the_dialog);
- Draw_Border(the_dialog, CHNG_OK, YES);
-
- SetPort(old_port);
-
- }
-
-
-
- /**********************************************************************
- * Function Draw_Abot_Dialog(), this function draws the objects in the
- * About dialog box.
- **********************************************************************/
-
- static pascal void Draw_Abot_Dialog(DialogRef the_dialog, short blank_item)
- {
-
- GrafPtr old_port;
-
- GetPort(&old_port);
- SetPort(the_dialog);
-
- Draw_Border(the_dialog, ABOUT_OK, YES);
-
- SetPort(old_port);
-
- }
-
-
-
- /**********************************************************************
- * Function Draw_Pref_Dialog, this function draws the information
- * in the Prefernces dialog box.
- **********************************************************************/
-
- static pascal void Draw_Pref_Dialog(DialogRef the_dialog, short blank_item)
- {
-
- short i;
- Rect item_rect;
- GrafPtr old_port;
-
- Draw_Border(the_dialog, PREF_DONE, YES);
-
- GetPort(&old_port);
- SetPort(the_dialog);
-
- PenSize(1, 1);
- for(i=2;i<=6;i++)
- {
- Get_Dialog_Item_Rect(the_dialog, i, &item_rect);
- FrameRect(&item_rect);
- }
-
- SetPort(old_port);
-
- if(Pref.menu_id==P_GENERL_ITEM) Draw_Pref_Gnrl(the_dialog, NIL_PTR);
-
- }
-
-
-
- /**********************************************************************
- * Function Draw_Pref_Gnrl(), this function draws the objects in the
- * Preference dialog box with respecto the General DITL.
- **********************************************************************/
-
- static pascal void Draw_Pref_Gnrl(DialogRef the_dialog, short blank_item)
- {
-
- Handle item_handle;
- short os=Pref.num_items;
- GrafPtr old_port;
-
- GetPort(&old_port);
- SetPort(the_dialog);
-
- Get_Dialog_Item_Hndl(the_dialog, os+P_GN_OKAC, &item_handle);
- SetControlValue((ControlHandle)item_handle, (**Global).AutoChange);
- Get_Dialog_Item_Hndl(the_dialog, os+P_GN_QADD, &item_handle);
- SetControlValue((ControlHandle)item_handle, (**Global).DragQuit);
-
- SetPort(old_port);
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Pref_Set_Up_DLOG(), this function appends the new
- * dialog items to the main preference dialog.
- **********************************************************************/
-
- void Handle_Pref_Set_Up_DLOG(DialogRef the_dialog, short the_ditl, short *ditl_count)
- {
-
- Handle ditl_handle;
-
- ditl_handle=GetResource( 'DITL', the_ditl);
-
- HLock(ditl_handle);
- AppendDITL(the_dialog, ditl_handle, overlayDITL);
- HUnlock(ditl_handle);
- ReleaseResource(ditl_handle);
-
- *ditl_count=CountDITL(the_dialog);
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Pref_Pop_Up_Menu(), this function updates
- * and sets up the pop-up menu which decides which dialog
- * items are displayed.
- **********************************************************************/
-
- void Handle_Pref_Pop_Up_Menu(Dialog_Info *the, short first_time)
- {
-
- Handle item_handle;
- short control_value, num_items;
-
- Get_Dialog_Item_Hndl(the->dialog, PREF_POPUP, &item_handle);
- control_value=GetControlValue((ControlHandle)item_handle);
- if(the->menu_id!=control_value)
- {
- the->menu_id=control_value;
- if(!first_time) ShortenDITL(the->dialog, CountDITL(the->dialog)-PREF_MAX_ITEMS);
- Handle_Pref_Set_Up_DLOG(the->dialog, PREF_DLOG_ID+the->menu_id, &num_items);
- Set_Dialog_Proc((Handle)proc_for_draw_Pref_dialog, the->dialog, num_items);
- switch(control_value)
- {
- case P_EPTYPE_ITEM:
- Make_Pop_Up_Menu(Edit.menu_id, Edit.pref_type, Edit.num_items);
- break;
- case P_EATYPE_ITEM:
- Make_Pop_Up_Menu(Auto.menu_id, Auto.pref_type, Auto.num_items);
- break;
- }
- }
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Pref_DITL_Item(), this function ACTUALLY decides where to
- * to direct an event if it wasn't for the main preference dialog items.
- **********************************************************************/
-
- void Handle_Pref_DITL_Item(Dialog_Info *the, short item_hit)
- {
-
- switch(the->menu_id)
- {
- case P_EPTYPE_ITEM:
- Switch_Pt_Dialog(the, item_hit);
- break;
- case P_EATYPE_ITEM:
- Switch_Ac_Dialog(the, item_hit);
- break;
- case P_GENERL_ITEM:
- Switch_Gnrl_Dialog(the, item_hit);
- break;
- }
-
- }
-
-
-
- /**********************************************************************
- * Function Get_Dialog_Text, this function gets text from a dialog
- * given the dialog and the item to get the text from.
- **********************************************************************/
-
- void Get_Dialog_Text(StringPtr the_string, DialogRef the_dialog, short the_item)
- {
-
- Handle item_handle;
-
- Get_Dialog_Item_Hndl(the_dialog, the_item, &item_handle);
- GetDialogItemText(item_handle, the_string);
-
- }
-
-
-
- /**********************************************************************
- * Function Set_Dialog_Proc(), this function attaches a procedure
- * to an item in a dialog.
- **********************************************************************/
-
- void Set_Dialog_Proc(Handle the_proc, DialogRef the_dialog, short the_item)
- {
-
- Handle item_handle;
- short item_type;
- Rect item_rect;
-
- GetDialogItem(the_dialog, the_item, &item_type, &item_handle, &item_rect);
- SetDialogItem(the_dialog, the_item, item_type, the_proc, &item_rect);
-
- }
-
-
-
- /**********************************************************************
- * Function Get_Dialog_Item_Hndl(), this function gets a handle to
- * a dialog item.
- **********************************************************************/
-
- void Get_Dialog_Item_Hndl(DialogRef the_dialog, short the_item, Handle *the_handle)
- {
-
- short item_type;
- Rect item_rect;
-
- GetDialogItem(the_dialog, the_item, &item_type, the_handle, &item_rect);
-
- }
-
-
-
- /**********************************************************************
- * Function Get_Dialog_Item_Rect(), this function gets the rect for
- * a dialog item.
- **********************************************************************/
-
- void Get_Dialog_Item_Rect(DialogRef the_dialog, short the_item, Rect *the_rect)
- {
-
- Handle item_handle;
- short item_type;
-
- GetDialogItem(the_dialog, the_item, &item_type, &item_handle, the_rect);
-
- }
-
-
-
- /**********************************************************************
- * Function Get_Dialog_Item_In_Rect(), this function determines if a
- * click was in a certain rect.
- **********************************************************************/
-
- Boolean Get_Dialog_Item_In_Rect(DialogRef the_dialog, short the_item, Point the_point)
- {
-
- Rect item_rect;
-
- Get_Dialog_Item_Rect(the_dialog, the_item, &item_rect);
- if(PtInRect(the_point, &item_rect)) return(YES);
- return(NO);
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Drag_Tracking(), this function handles the tracking
- * of the drag over the particular dialog box.
- **********************************************************************/
-
- pascal OSErr Handle_Drag_Tracking(short the_message, WindowRef the_dialog, void *handlerRefCon, unsigned long the_drag)
- {
-
- unsigned short the_count;
- unsigned long the_attributes;
- short the_result;
-
- GetDragAttributes(the_drag, &the_attributes);
-
- switch(the_message)
- {
- case dragTrackingEnterHandler:
- break;
- case dragTrackingEnterWindow:
- break;
- case dragTrackingInWindow:
- {
- RgnHandle the_rgn;
- Point the_point, the_local_point;
- Rect the_rect;
-
- GetDragMouse(the_drag, &the_point, NIL_PTR);
- the_local_point=the_point;
- GlobalToLocal(&the_local_point);
-
- if(the_attributes & dragHasLeftSenderWindow)
- {
- if(PtInRect(the_local_point, &the_dialog->portRect))
- {
- RectRgn(the_rgn=NewRgn(), &the_dialog->portRect);
- ShowDragHilite(the_drag, the_rgn, true);
- DisposeRgn(the_rgn);
- }
- else HideDragHilite(the_drag);
- }
- }
- break;
- case dragTrackingLeaveWindow:
- HideDragHilite(the_drag);
- break;
- case dragTrackingLeaveHandler:
- break;
- }
- return(noErr);
- }
-
-
-
- /**********************************************************************
- * Function Handle_Drag_Receive_Drop(), this function handles what
- * happens when the drag is dropped on the dialog.
- **********************************************************************/
-
- pascal OSErr Handle_Drag_Receive_Drop(WindowRef the_dialog, void *handlerRefCon, unsigned long the_drag)
- {
-
- unsigned short the_count;
- ItemReference the_item;
- FlavorFlags the_flags;
- Str4 the_c_type, the_f_type;
- HFSFlavor *the_hfs_flavor;
- OSType folder1='fold', disk='disk', folder2='fdrp';
- Size the_size;
-
- CountDragItems(the_drag, &the_count);
-
- if(the_count==1)
- {
- GetDragItemReferenceNumber(the_drag, the_count, &the_item);
- GetFlavorDataSize(the_drag, the_item, flavorTypeHFS, &the_size);
- the_hfs_flavor=(HFSFlavor *)NewPtr(the_size);
- GetFlavorData(the_drag, the_item, flavorTypeHFS, the_hfs_flavor, &the_size, NIL_PTR);
-
- if( (the_hfs_flavor->fileType!=folder1) && (the_hfs_flavor->fileType!=disk)&& (the_hfs_flavor->fileType!=folder2) )
- {
- Set_Type_Text(the_f_type, the_hfs_flavor->fileType);
- Set_Type_Text(the_c_type, the_hfs_flavor->fileCreator);
-
- if(the_dialog==Chng.dialog)
- {
- Set_DLOG_Text_Item(the_dialog, CHNG_FILE, the_f_type);
- Set_DLOG_Text_Item(the_dialog, CHNG_CREATOR, the_c_type);
- }
- else if(the_dialog==Pref.dialog)
- if(Pref.menu_id==P_EPTYPE_ITEM)
- {
- Set_DLOG_Text_Item(the_dialog, P_PT_CT+PREF_MAX_ITEMS, the_c_type);
- Set_DLOG_Text_Item(the_dialog, P_PT_FT+PREF_MAX_ITEMS, the_f_type);
- }
- else if(Pref.menu_id==P_EATYPE_ITEM)
- {
- Set_DLOG_Text_Item(the_dialog, P_AC_CHFT+PREF_MAX_ITEMS, the_f_type);
- Set_DLOG_Text_Item(the_dialog, P_AC_CTCT+PREF_MAX_ITEMS, the_c_type);
- Set_DLOG_Text_Item(the_dialog, P_AC_CTFT+PREF_MAX_ITEMS, the_f_type);
- }
- }
- DisposePtr((Ptr)the_hfs_flavor);
- }
-
- return(noErr);
-
- }